package util

import (
	"os"
	"path/filepath"
	"strings"
)

func HasSuffixOr(source string, suffixes []string) bool {
	for _, suffix := range suffixes {
		if strings.HasSuffix(source, suffix) {
			return true
		}
	}
	return false
}

func Exist(path string) bool {
	if _, err := os.Stat(path); err != nil {
		if os.IsNotExist(err) {
			return false
		}
	}
	return true
}

func GetJreDir(jreOption string) string {
	if jreOption != "" && Exist(jreOption) {
		return jreOption
	}

	if Exist("./jre") {
		return "./jre"
	}

	if jh := os.Getenv("JAVA_HOME"); jh != "" {
		return filepath.Join(jh, "jre")
	}
	panic("Can not find jre folder!")
}
